package com.util;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Util {
	public static Connection getConnection(){
		final String _DRIVER = "oracle.jdbc.driver.OracleDriver";
		final String _URL    = "jdbc:oracle:thin:@172.16.10.133:1521:orcl10";
		final String _USER   = "scott";
		final String _PW     = "tiger";
		Connection con = null;
		try {
			Class.forName(_DRIVER);
			con = DriverManager.getConnection(_URL, _USER, _PW);
		} catch (ClassNotFoundException ce) {
			System.out.println("Exception:"+ce.toString());
		} catch (SQLException se) {
			System.out.println("Exception:"+se.toString());
		} catch (Exception e){
			System.out.println("Exception:"+e.toString());
		}
		return con;
	}
	public static void freeConnection(Connection con, Statement stmt){
		try {
			if(stmt !=null) stmt.close();
			if(con !=null) con.close();
		} catch (Exception e2) {
			System.out.println("Exception:"+e2.toString());
		}			
	}
	public static void freeConnection(Connection con, PreparedStatement pstmt){
		try {
			if(pstmt !=null) pstmt.close();
			if(con !=null) con.close();
		} catch (Exception e2) {
			System.out.println("Exception:"+e2.toString());
		}			
	}
	public static void freeConnection(Connection con, CallableStatement cstmt){
		try {
			if(cstmt !=null) cstmt.close();
			if(con !=null) con.close();
		} catch (Exception e2) {
			System.out.println("Exception:"+e2.toString());
		}			
	}
	public static void freeConnection(Connection con, Statement stmt, ResultSet rs){
		try {
			if(rs !=null) rs.close();
			if(stmt !=null) stmt.close();
			if(con !=null) con.close();
		} catch (Exception e2) {
			// TODO: handle exception
		}		
	}
}












